from rest_framework import serializers
from goods.models import Goods, Brand, GoodsCategory, GoodsSpecification


# SKU表数据
class SPUSerializer(serializers.ModelSerializer):
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    class Meta:
        model=Goods
        exclude = ('category1', 'category2', 'category3')

# 获取SPU表名称数据
class SpuSerializer(serializers.ModelSerializer):
    class Meta:
        model=Brand
        fields='__all__'

# 获取商品级别分类信息
class SPUCategorieSerializer(serializers.ModelSerializer):

    class Meta:
        model = GoodsCategory
        exclude = ('create_time', 'update_time')

# 获取规格表数据
class GoodssSpecsSerializer(serializers.ModelSerializer):
    spu_id = serializers.IntegerField()
    spu = serializers.StringRelatedField()
    class Meta:
        model=GoodsSpecification
        fields='__all__'